/*
 * @lc app=leetcode.cn id=435 lang=swift
 *
 * [435] 无重叠区间
 */

// @lc code=start
class Solution {
    func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {
        let sortIntervals = intervals.sorted(by: { $0[1] < $1[1] })

        var remove = 0
        var prefix = sortIntervals[0][1]
        for i in 1..<sortIntervals.count {
            if sortIntervals[i][0] < prefix {
                remove += 1
            } else {
                prefix = sortIntervals[i][1]
            }
        }

        return remove
    }
}
// @lc code=end

